<style lang="scss" scoped>
.urcode {
    position: fixed;
    top: -99999px;
    left: 0;
    background-color: red;
}
</style>
<template>
    <view class="urcode">
        <canvas class="urcode" canvas-id="qrcode" :style="'width:150px'" />
    </view>
</template>

<script setup lang='ts'>
import { reactive, ref } from "vue";
import { onLoad, onShow, onPullDownRefresh } from "@dcloudio/uni-app";
import uQRCode from "./urcode";
const shengcheng = (text) => {
    return new Promise((reslove, reject) => {
        uQRCode.make({
            canvasId: "qrcode", // canvas-id
            componentInstance: this, // 传入组件实例
            text: text,
            size: 150,
            margin: 0, // 二维码四周自动留边宽度，不传入默认为0
            backgroundColor: "#ffffff",
            // foregroundColor: "#fa8d50",
            //随机颜色
            foregroundColor:
                "#" + Math.floor(Math.random() * 16777215).toString(16),
            fileType: "png", // 导出的图片类型，只支持 jpg 和 png
            errorCorrectLevel: uQRCode.errorCorrectLevel.H, // 纠错等级
            success: (res) => {
                reslove(res);
            },
            fail: (err) => {
                // 失败回调
                reject(err);
            },
            complete: () => {
                // 接口调用结束的回调函数（调用成功、失败都会执行）
                // console.log("complete");
            },
        });
    });
};
// 暴露方法
defineExpose({ shengcheng });
</script>